<?php
	ini_set('include_path', dirname(dirname(__FILE__)));
require_once(get_include_path().'/libraries/load.php');


$str_method = '';
try{
	$method = $_POST['method'];
	$params = json_decode(stripslashes($_POST['params']));
	$returnData = $_POST['returnData'];
	$start = (int)$_POST['start'];
	$limit = (int)$_POST['limit'];
	
	$str_method = $method.'(';
	for( $i = 0; $i < count($params); $i++ ){
		if($i > 0)$comma = ',';
		switch(gettype($params[$i])){
			case 'string':
				$str_method .= $comma .'\'' .$params[$i] .'\'';
				break;				
			default:
				$str_method .= $comma . $params[$i];
				break;
		}
	}
	$str_method .= ');';
	if($returnData == 'true'){
		$res = eval('return '.$str_method);
		$store = new storeResult();
		$store->totalCount = count($res);

		if( $start >= 0 && $limit > 0)
			$res = array_slice($res,$start, $limit);
		$store->values = $res;
		echo json_encode($store);
	}else{
		eval($str_method);
		echo '{success:true}';
	}
}catch(Exception $ex){
	echo '{success:false, method: \''. $str_method.'\', message: \''. $ex->getMessage().'\'}';
}

class storeResult{
	public $totalCount;
	public $values;
}
?>